home *** CD-ROM | disk | FTP | other *** search
/ Shareware Grab Bag / Shareware Grab Bag.iso / 007 / boosters.arc / TIMER.PAS < prev    next >
Pascal/Delphi Source File  |  1985-11-03  |  2KB  |  59 lines

  1. { ----------------------
  2.   TIMER Boolean Function
  3.   ---------------------- }
  4. Function Timer ( Limit : integer) : Boolean;
  5.  
  6. { Note: Globals are:
  7.                  Type
  8.                     Result  = record
  9.                                 AX, BX, CX, DX, BP,
  10.                                 SI, DI, DS, ES, Flags : Integer;
  11.                               end;
  12.                  var
  13.                     regs : result;
  14.                     TimeElapsed,
  15.                     SaveElapsed   : Integer;
  16.                     StartElapsed  : Boolean = FALSE;
  17. }
  18. var
  19.    SecondsReading : Integer;
  20.  
  21. begin
  22.    with regs do
  23.    begin
  24.       if Limit <= 0 then
  25.          Timer := TRUE
  26.       else
  27.       begin
  28.          Timer := FALSE;
  29.          ax := $2C00;
  30.          intr($21,regs);
  31.  
  32.          if StartElapsed = FALSE then
  33.          begin
  34.             SaveElapsed  := hi(dx);
  35.             TimeElapsed  := 0;
  36.             StartElapsed := TRUE;
  37.             ax := $2D00;                { Set time . . .            }
  38.             dx := Swap(SaveElapsed);    { With hundredths = 0 . . . }
  39.             intr($21,regs);             { so that we start from 0   }
  40.             delay(70);                  { Helps DOS 3.1 work right  }
  41.          end
  42.          else
  43.          if SaveElapsed <> hi(dx) then
  44.          begin
  45.             SecondsReading := hi(dx);
  46.             if SaveElapsed > SecondsReading then
  47.                SecondsReading := SecondsReading + 60;
  48.             TimeElapsed := TimeElapsed + SecondsReading - SaveElapsed;
  49.             SaveElapsed := hi(dx);
  50.  
  51.             if TimeElapsed >= Limit then
  52.             begin
  53.                Timer := TRUE;
  54.                StartElapsed := FALSE;
  55.             end;
  56.          end;
  57.       end;
  58.    end;
  59. end { Timer };